package com.example.cet4try.adapter;

import android.content.Context;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;


import com.example.cet4try.R;
import com.example.cet4try.Utils.WordClass;

import java.util.List;

public class WordListAdapter extends BaseRecyclerViewAdapter<WordClass> {

    private OnDeleteClickLister mDeleteClickListener;
    private OnClickListener mOnClickListener;

    public WordListAdapter(Context context, List<WordClass> data) {
        super(context, data, R.layout.word_list_liem);
    }

    @Override
    protected void onBindData(RecyclerViewHolder holder, WordClass bean, int position) {
        View view = holder.getView(R.id.tv_delete);
        view.setTag(position);
        if (!view.hasOnClickListeners()) {
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mDeleteClickListener != null) {
                        mDeleteClickListener.onDeleteClick(v, (Integer) v.getTag());
                    }
                }
            });
        }
        ((TextView) holder.getView(R.id.tv_english)).setText(bean.getEnglish());
        ((TextView) holder.getView(R.id.tv_chinese)).setText(bean.getChinese());

        RelativeLayout t_item = (RelativeLayout) holder.getView(R.id.t_item);
        t_item.setTag(position);
        t_item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnClickListener != null){
                    mOnClickListener.onClick(v, (Integer) v.getTag());
                }
            }
        });

    }

    public void setOnDeleteClickListener(OnDeleteClickLister listener) {
        this.mDeleteClickListener = listener;
    }

    public interface OnDeleteClickLister {
        void onDeleteClick(View view, int position);
    }

    public void setOnClickListener(OnClickListener OnClickListener) {
        this.mOnClickListener = OnClickListener;
    }

    public interface OnClickListener{
        void onClick(View view,int position);
    }

}
